//获取应用实例
var app = getApp();
const $ = require('../../utils/utils');
const config = require('../../config');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        returnCount: 0,
        borrowCount: 0,
        borrowList: "",
        transAmount: 0.00,
        tip_content: '在借图书超过三本，我们会需要您支付额外的超额费用!',
        shelfCode: "",
        showLotteryPopup: false
    },

    /**
    * 生命周期函数--监听页面加载
    */
    onLoad: function (options) {
        var that = this;
        that.borrowreturnv2();
        that.configTip();
    },

    return_repair_pager: function () {
        wx.showModal({
            title: "盘点错误",
            content: '4009216933',
            cancelText: "报修",
            confirmText: "拨打",
            cancelColor: "#338af0",
            confirmColor: "#f95851",
            success: function (res) {
                if (res.confirm) {
                    wx.makePhoneCall({
                        phoneNumber: config.servicePhone
                    });
                } else if (res.cancel) {
                    let repairPath = config.page.repair + "?maintain_type=30&" + "path=borrow_success"
                    $.goto(repairPath)
                }
            }
        });
    },

    return_page: function () {
        $.goto(config.page.index + '?path="borrow"', true)
    },
    // 获取书库列表接口
    borrowreturnv2: function (data) {
        var userid = wx.getStorageSync('userid');
        var usertoken = wx.getStorageSync('usertoken');
        var getData = "userid=" + userid + "&usertoken=" + usertoken;
        $.get((config.borrowreturnv2 + "?" + getData)).then(data => {
            console.log('borrow_success_data_drawTip', parseInt(data.detail.drawTip));
            this.setData({
                borrowList: data.detail.list,
                returnCount: data.detail.returnCount,
                transAmount: data.detail.transAmount,
                borrowCount: data.detail.borrowCount,
            });

            if (parseInt(data.detail.drawTip) == 1){
                this.setData({
                    showLotteryPopup: true
                })
            }
            if (data.detail.tip) {
                wx.showModal({
                    content: data.detail.tip,
                    showCancel: false,
                    confirmColor: "#FF3B30",
                    confirmText: "我知道了"
                });
            }
        })
    },

    configTip: function () {
        if (wx.getStorageSync('VIP_Type') == 1) {
            this.setData({
                tip_content: '普通会员和月卡会员在借限3本,超出会有额外费用!'
            })
        } else if (wx.getStorageSync('VIP_Type') == 2) {
            this.setData({
                tip_content: '年卡会员在借限5本, 超出会有额外费用!'
            })
        }
    },


    dismissPopup: function () {
        this.setData({
            showLotteryPopup: false
        })
    },

    toLotteryPage: function () {
        wx.setStorageSync('isToLottery',true)
        $.goto(config.page.index, true)
    }

})